package com.bestv.search.common.dao.hibernate;

import com.bestv.search.common.dao.SubTypeDao;
import com.bestv.search.common.model.SubType;

import java.util.List;

public class SubTypeDaoHibernate extends GenericDaoHibernate<SubType, Long> implements SubTypeDao {

    public SubTypeDaoHibernate() {
        super(SubType.class);
    }

    public SubType getSubTypeById(Long id) {
        return super.get(id);
    }

    @SuppressWarnings("unchecked")
    public SubType getSubTypeByName(String name) {
        List<SubType> list = getHibernateTemplate().find("from SubType s where s.name = ?", name);
        if (list == null || list.size() == 0) {
            return null;
        }
        return list.get(0);
    }

    public List<SubType> getSubTypes() {
        return super.getAll();
    }

    public SubType saveSubType(SubType subType) {
        return super.save(subType);
    }

    @SuppressWarnings("unchecked")
    public List<SubType> getComm() {
        return getHibernateTemplate().find("from SubType s where s.name = '商品'");
    }
}
